var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope,$http,$timeout){
	//提示框
	$scope.reminder = false;
	$scope.close = function(){
		$scope.reminder = false;
	}
	
	$scope.name = "";       //收件人
	$scope.mobile = "";     //手机
	$scope.phone = "";      //固话
	$scope.province = "";   //省份
	$scope.city = "";       //城市
	$scope.county = "";     //区
	$scope.detailedAddress = ""  //详细地址
	$scope.code = "";       //邮政编码
	
	$scope.no = false;
	$scope.src = "image/未选中.png";
	$scope.a = false;
	$scope.checked = function(){
		$scope.a = !$scope.a;
		if($scope.a == true){
			$scope.src = "image/选中.png";
		}else{
			$scope.src = "image/未选中.png";
		}
	}
	
	$scope.addAddress = function(){
		if($scope.name.length == 0 || $scope.name.length>10){
			$scope.no = true; 
			$scope.message = "用户名为1到10的字符";
			$timeout(function(){
        		$scope.no = false;
        	},750);
			return;
		}
		if(!/^1[3|4|5|7|8][0-9]\d{8}$/.test($scope.mobile)){
			$scope.no = true; 
			$scope.message = "手机格式不正确";
			$timeout(function(){
        		$scope.no = false;
        	},750);
			return;
		}
		if($scope.detailedAddress == ""){
			$scope.no = true; 
			$scope.message = "详细地址不能为空";
			$timeout(function(){
        		$scope.no = false;
        	},750);
			return;
		}
		if($scope.code == ""){
			$scope.no = true; 
			$scope.message = "邮政编码不能为空";
			$timeout(function(){
        		$scope.no = false;
        	},750);
			return;
		}
		$scope.province = $("#s_province").val();
		$scope.city = $("#s_city").val();
		$scope.county = $("#s_county").val();
		console.log($scope.name+" "+$scope.mobile+" "+$scope.phone+" "+$scope.province+" "+$scope.city+" "+$scope.county+" "+$scope.detailedAddress+" "+$scope.code)
	
	    var params = {
			fullName : $scope.name,  
		    mobile : $scope.mobile,
		    phone : $scope.phone,
		    province : $scope.province,
		    city : $scope.city,
		    district :$scope.county,
		    address : $scope.detailedAddress,
		    zip : $scope.code
		};
		params = $.param(params);
		$http({
	        method : "post",
	        dataType: "json",
			withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
		    crossDomain: true,
		    headers:{'Content-Type': 'application/x-www-form-urlencoded'},
		    data: params,
	        //async:true,
	        url : host + "/terminal/shipping/add"
	   }).success(function(response){
	        if(response.code == 2000){
	        	$scope.reminder = true;
	        	$scope.message = response.message;
	        }
	    }).error(function(response){
	    	console.log(response);
	    });
	    
	    if($scope.a == true){
	    	
	    }
	}
	
	
})